<?php
declare (strict_types = 1);

namespace app\admin\controller;

use think\response\Json;
use think\facade\Db;
use think\facade\Request;
/**
 * 控制台
 * Class Index
 * @package app\admin\controller
 */
class Index extends Controller
{
    /**
     * 统计数据
     * @return Json
     */
    public function datas(): Json
    {
        $domain = Request::domain();
        $today = strtotime(date('Y-m-d 00:00:00'));
        $data = [
            [
                'icon' => $domain.'/static/icons/user.svg',
                'title' => '用户数',
                'totalTitle' => '总用户数',
                'value' => Db::name('user')->where([
                    ['create_time', '>=', $today],
                    ['create_time', '<', $today + 86400]
                ])->count(),
                'totalValue' => Db::name('user')->where('status', 1)->count(),
            ],
            [
                'icon' => $domain.'/static/icons/useractive.svg',
                'title' => '活跃用户',
                'totalTitle' => '七日活跃用户',
                'value' => Db::name('user')->where([
                    ['last_login_time', '>=', $today],
                    ['last_login_time', '<', $today + 86400]
                ])->count(),
                'totalValue' => Db::name('user')->where([
                    ['last_login_time', '>=', $today - 86400*6],
                    ['last_login_time', '<', $today + 86400]
                ])->count(),
            ],
            [
                'icon' => $domain.'/static/icons/recharge_log.svg',
                'title' => '充值记录',
                'totalTitle' => '总充值记录',
                'value' => Db::name('recharge_order')->where([
                    ['create_time', '>=', $today],
                    ['create_time', '<', $today + 86400],
                    ['pay_status', '=', 20]
                ])->count(),
                'totalValue' => Db::name('recharge_order')->count(),
            ],
            [
                'icon' => $domain.'/static/icons/zc_money.svg',
                'title' => '充值金额',
                'totalTitle' => '总充值金额',
                'value' => Db::name('recharge_order')->where([
                    ['create_time', '>=', $today],
                    ['create_time', '<', $today + 86400],
                    ['pay_status', '=', 20]
                ])->sum('pay_price'),
                'totalValue' => Db::name('recharge_order')->sum('pay_price'),
            ]
        ];
        return $this->renderSuccess($data);
    }
    /**
     * 系统信息
     * @return Json
     */
    public function systemdata(): Json
    {
        return $this->renderSuccess([
            [
                'key' => '服务器域名',
                'value' => Request::host()
            ],
            [
                'key' => '服务器操作系统',
                'value' => PHP_OS
            ],
            [
                'key' => '服务器编译引擎',
                'value' => $_SERVER['SERVER_SOFTWARE']
            ],
            [
                'key' => 'PHP版本',
                'value' => PHP_VERSION
            ],
            [
                'key' => '系统安装目录',
                'value' => getcwd()
            ],
            [
                'key' => '版本号',
                'value' => 'v1.0.0'
            ]
        ]);
    }
    /**
     * 快捷导航
     * @return Json
     */
    public function quicklink(): Json
    {
        return $this->renderSuccess([
            [
                'color' => '#1fdaca',
                'icon' => 'ion:settings-outline',
                'title' => '系统设置',
                'url' => '/system/setting',
            ],
            [
                'color' => '#df0c2c',
                'icon' => 'ant-design:bars-outlined',
                'title' => '菜单管理',
                'url' => '/system/menu',
            ],
            [
                'color' => '#e18525',
                'icon' => 'ant-design:solution-outlined',
                'title' => '个人中心',
                'url' => '/system/profile',
            ],
            [
                'color' => '#4daf1bc9',
                'icon' => 'ant-design:user-outlined',
                'title' => '用户列表',
                'url' => '/user/list',
            ],
            [
                'color' => '#00d8ff',
                'icon' => 'ant-design:pay-circle-outlined',
                'title' => '余额明细',
                'url' => '/user/balance',
            ],
            [
                'color' => '#FFd800',
                'icon' => 'ant-design:star-outlined',
                'title' => '积分明细',
                'url' => '/user/points',
            ]
        ]);
    }
}
